Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:add plugin-lightning #2429

Merged
merged 19 commits into from
Jan 20, 2025
Merged

Conversation

jimtracy1007
Copy link
Contributor

@jimtracy1007 jimtracy1007 commented Jan 17, 2025

@elizaos/plugin-lightning

This plugin enables create lightning invoice or payInvoice.

Features

  • 💱 Make a new off-chain invoice.
  • 📊 Make an off-chain payment.

Installation

Add the plugin to your Eliza configuration:

{
    "plugins": ["@elizaos/plugin-lightning"]
}

Configuration

Set the following environment variables:

LND_TLS_CERT=your_lnnode_tls_cert   #Base64 of LND certificate
LND_MACAROON=020.....        #Base64 encoded admin.macaroon file
LND_SOCKET='x.x.x.x:10009'

Available Actions

1. CREATE_INVOICE

Make a new off-chain invoice.

Examples:


"Help me create an invoice for 1000sats"
"Create an invoice for 1000sats"

Returns: lnbcrt....

2. PAY_INVOICE

Make an off-chain payment.

Examples:


"Pay invoice lnbcrt10u1pncndjvpp58y77adkngcz3ypx6t39j245ydvk2vu67c8ugvegee3gt5wgs7yjqdxvdec82c33wdmnq73s0qcxwurrxp4nquncxe4h56m9xu6xwetyd3mrq6ehdguxkd35wuurgarex4u8gefkdsekgdtnddehxurrxecxvhmwwp6kyvfexekhxwtv8paryvnpwsuhxdryvachwangw3kn2atddq6kzvrvwfcxzanewce8ja34d43k56rkweu8jdtcwv68zmrsvdescqzzsxqrrsssp5q3hv38wfprvaazzwf8c4t33tzjcac5xz94sk8muehmn5szqaw6ks9qxpqysgqt5pjhna4922s8ayzgu5rh8clx7psp2culdr5r6cxxxqzs3e5ep345p45vggg0qegt6fu3prdrqgpd8v70l9wdhekt8gex5e8pqvxg2sp97fkmd"


Security Notes

  • Store your LND_TLS_CERT and LND_MACAROON securely using environment variables
  • Test with small amounts first
  • Use regtest for initial testing

License

MIT


Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jimtracy1007! Welcome to the elizaOS community. Thanks for submitting your first pull request; your efforts are helping us accelerate towards AGI. We'll review it shortly. You are now an elizaOS contributor!

@wtfsayo
Copy link
Member

wtfsayo commented Jan 17, 2025

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Jan 17, 2025

📝 Walkthrough

Walkthrough

The pull request introduces a new Lightning Network plugin for the Eliza agent, enabling off-chain payment functionality. The plugin integrates with LND (Lightning Network Daemon) and provides actions for creating and paying invoices. It includes a comprehensive package with TypeScript configurations, provider implementations, and action handlers. The changes extend the agent's capabilities by adding Lightning Network support through a modular and configurable plugin architecture.

Changes

File Change Summary
agent/package.json Added @elizaos/plugin-lightning as a workspace dependency
agent/src/index.ts Imported lightningPlugin and conditionally added to agent plugins
packages/plugin-lightning/... New plugin package with comprehensive implementation:
- README documentation
- ESLint and TypeScript configurations
- Actions for invoice creation and payment
- Lightning provider implementation
- Type definitions
turbo.json Added build task for Lightning plugin

Finishing Touches

  • 📝 Generate Docstrings (Beta)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 12

🧹 Nitpick comments (7)
packages/plugin-lightning/src/actions/payInvoice.ts (2)

82-83: Redundant 'outgoing_channel' parameter

In payInvoiceOptions, passing outgoing_channel is unnecessary since it's determined within the payInvoice method.


92-95: Simplify callback messages

You can streamline the construction of callback messages for clarity.

Consider:

     if (payInvoiceResp.is_confirmed) {
-        text = `Successfully payInvoice ${content.request} from ${payInvoiceResp.outgoing_channel};\r\n Amount: ${payInvoiceResp.tokens};\r\n Fee: ${payInvoiceResp.fee};\r\n Payment Hash: ${payInvoiceResp.id};`;
+        callback({
+            text: `Successfully paid invoice ${content.request} from ${payInvoiceResp.outgoing_channel};\nAmount: ${payInvoiceResp.tokens};\nFee: ${payInvoiceResp.fee};\nPayment Hash: ${payInvoiceResp.id};`,
+            content: { success: true },
+        });
     } else {
-        text = `Failed to payInvoice ${content.request} from ${content.outgoing_channel};\r\n Amount: ${payInvoiceResp.tokens};`;
+        callback({
+            text: `Failed to pay invoice ${content.request} from ${content.outgoing_channel};\nAmount: ${payInvoiceResp.tokens};`,
+            content: { success: false },
+        });
     }
-    callback({
-        text: text,
-        content: {
-            success: true,
-        },
-    });
packages/plugin-lightning/src/index.ts (2)

8-8: Unused import 'lndProvider'

The lndProvider import is unused. Remove it to clean up the code.

Apply this diff:

-import { lndProvider } from "./providers/lightning";

13-15: Omit empty arrays

The evaluators and services arrays are empty. You can omit them for brevity.

     description: "lightning integration plugin",
-    providers: [lndProvider],
+    providers: [],
-    evaluators: [],
-    services: [],
     actions: [createInvoiceAction, payInvoiceAction],
packages/plugin-lightning/src/providers/lightning.ts (1)

74-74: Improve string template formatting

The current string concatenation could be improved.

-            return `${agentName}'s Lightning Node publickey : ${nodePubkey}\n,Channel count : ${channels.length}`;
+            return `${agentName}'s Lightning Node publickey: ${nodePubkey}\nChannel count: ${channels.length}`;
packages/plugin-lightning/src/actions/createInvoice.ts (1)

70-70: Format token amount in success message

Raw token values should be formatted for better readability.

-                    text: `Successfully createInvoice ${createInvoiceResp.tokens}\r\nInvoice:${createInvoiceResp.request}`,
+                    text: `Successfully created invoice for ${createInvoiceResp.tokens.toLocaleString()} sats\r\nInvoice: ${createInvoiceResp.request}`,
packages/plugin-lightning/README.md (1)

38-44: Add language specifiers to code blocks.

Code blocks should specify their language for proper syntax highlighting.

Apply these changes:

  • Line 38: Add text specifier
  • Line 53: Add text specifier
  • Line 70-72: Remove empty code block

Also applies to: 53-59, 70-72

🧰 Tools
🪛 Markdownlint (0.37.0)

38-38: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c4d173d and 162e611.

📒 Files selected for processing (14)
  • agent/package.json (1 hunks)
  • agent/src/index.ts (2 hunks)
  • packages/plugin-lightning/README.md (1 hunks)
  • packages/plugin-lightning/eslint.config.mjs (1 hunks)
  • packages/plugin-lightning/package.json (1 hunks)
  • packages/plugin-lightning/src/actions/createInvoice.ts (1 hunks)
  • packages/plugin-lightning/src/actions/payInvoice.ts (1 hunks)
  • packages/plugin-lightning/src/index.ts (1 hunks)
  • packages/plugin-lightning/src/providers/lightning.ts (1 hunks)
  • packages/plugin-lightning/src/templates/index.ts (1 hunks)
  • packages/plugin-lightning/src/types/index.ts (1 hunks)
  • packages/plugin-lightning/tsconfig.json (1 hunks)
  • packages/plugin-lightning/tsup.config.ts (1 hunks)
  • turbo.json (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • packages/plugin-lightning/eslint.config.mjs
  • packages/plugin-lightning/tsconfig.json
🧰 Additional context used
🪛 Markdownlint (0.37.0)
packages/plugin-lightning/README.md

38-38: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)


53-53: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)


70-70: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🔇 Additional comments (5)
packages/plugin-lightning/tsup.config.ts (1)

13-22: Review external dependencies

Verify that all necessary dependencies are correctly externalized to prevent bundling issues.

agent/src/index.ts (1)

857-861: Verify environment variables before enabling the plugin.

The plugin activation depends on three environment variables. Let's verify their presence and format.

turbo.json (1)

52-55: LGTM!

The build configuration follows the established pattern and correctly specifies the dependency on plugin-tee.

agent/package.json (2)

95-95: LGTM! Dependency properly placed.

The new Lightning plugin dependency:

  • Uses the correct workspace syntax
  • Follows alphabetical ordering
  • Is placed in the appropriate dependencies section

95-95: Verify Lightning plugin security configuration.

Since this plugin handles financial transactions, ensure that the required environment variables (LND_TLS_CERT, LND_MACAROON, LND_SOCKET) are properly secured and not exposed in logs or error messages.

Consider implementing:

  1. Environment variable validation at startup
  2. Secure error handling that doesn't leak sensitive data
  3. Rate limiting for invoice creation

@wtfsayo
Copy link
Member

wtfsayo commented Jan 17, 2025

can you fix these @jimtracy1007

wtfsayo and others added 4 commits January 17, 2025 20:46
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@wtfsayo
Copy link
Member

wtfsayo commented Jan 17, 2025

@coderabbitai mustuse elizaLogger

Copy link
Contributor

coderabbitai bot commented Jan 17, 2025

Tip

For best results, initiate chat on the files or code changes.

@wtfsayo Here are the changes needed to use elizaLogger instead of console.log:

  1. Add import in both files:
import { elizaLogger } from "@elizaos/core";
  1. Replace console.log calls:

In src/actions/payInvoice.ts:

elizaLogger.log("payInvoice action handler called");
elizaLogger.log("🚀 ~ payInvoiceResp:", payInvoiceResp);

In src/actions/createInvoice.ts:

elizaLogger.log("CreateInvoice action handler called");
🔗 Analysis chain
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# First, find the proper import path for elizaLogger
ast-grep --pattern 'import { $_ as elizaLogger } from "$_"'

# Then find direct elizaLogger usage to understand the pattern
ast-grep --pattern 'elizaLogger.$_($_)'

# Look for console.log usage in the new plugin
rg "console\.log" packages/plugin-lightning/

Length of output: 65853


Script:

#!/bin/bash
# Look for console.log usage specifically in the lightning plugin
rg "console\.log" packages/plugin-lightning/

Length of output: 387


✏️ Learnings added
Learnt from: wtfsayo
URL: https://github.com/elizaOS/eliza/pull/2429

Timestamp: 2025-01-17T15:18:59.820Z
Learning: Always use elizaLogger from @elizaos/core instead of console.log for logging in Eliza plugins. elizaLogger provides different log levels: log, error, warn, success, info, and debug.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

wtfsayo and others added 6 commits January 18, 2025 21:25
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@wtfsayo wtfsayo enabled auto-merge (squash) January 18, 2025 16:04
@wtfsayo wtfsayo self-requested a review January 18, 2025 16:04
@jimtracy1007
Copy link
Contributor Author

can you fix these @jimtracy1007

Ok,I will fix it.

auto-merge was automatically disabled January 20, 2025 02:44

Head branch was pushed to by a user without write access

@jimtracy1007
Copy link
Contributor Author

@wtfsayo I have fixed the related issues. Please review and merge them again. Thank you.

@wtfsayo wtfsayo enabled auto-merge (squash) January 20, 2025 07:16
@wtfsayo wtfsayo merged commit 4d5be44 into elizaOS:develop Jan 20, 2025
3 checks passed
mgunnin added a commit to mgunnin/eliza-agent that referenced this pull request Jan 20, 2025
* upstream/develop:
  test configuration and tests for client-lens (elizaOS#2534)
  chore(attempt): optimize pnpm cache configuration (elizaOS#2556)
  feat: add a way to create/store/restore agents in the filesystem (elizaOS#2389)
  chore: optimize pnpm cache configuration (elizaOS#2555)
  chore: remove cleanup step from integration tests workflow (elizaOS#2553)
  feat: Add more actions to Abstract Plugin (elizaOS#2531)
  feat: add anthropic image provider for vision (elizaOS#2524)
  feat: improve integrationtests workflow caching (elizaOS#2551)
  feat: Updated READ.me file with pre-requisites to enable telegram bot (elizaOS#2547)
  feat(plugin-devin): implement client-agnostic Devin plugin (elizaOS#2549)
  use generateObject
  handle undefined env variable
  feat:add plugin-lightning (elizaOS#2429)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants